package com.star.eastern.blee

import android.support.v7.app.AppCompatActivity
import android.os.Bundle
import android.support.v7.widget.LinearLayoutManager
import android.support.v7.widget.RecyclerView
import android.util.Log
import android.widget.Button
import com.star.eastern.blee.utils.LogAdapter
import com.star.eastern.blee.utils.LogConsole

class ViewLogActivity : AppCompatActivity() {
    var vwLogList:RecyclerView? = null
    var vwReturn:Button? = null
    var vwClear:Button? = null
    var adapter:LogAdapter? = null


    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_view_log)
        initView()
        initListen()
    }

    private fun initView(){
        vwLogList = findViewById(R.id.recycler_list)
        vwReturn = findViewById(R.id.btn_return)
        vwClear = findViewById(R.id.btn_clear)
        adapter = LogAdapter(this,LogConsole.logList)
        val layoutManager = LinearLayoutManager(this)
        layoutManager.orientation = LinearLayoutManager.VERTICAL
        vwLogList!!.layoutManager = layoutManager
        Log.d("console","itemCount  =  " + adapter!!.itemCount.toString())
        vwLogList!!.adapter = adapter
    }

    private fun initListen(){
        vwReturn!!.setOnClickListener {
            this.finish()
        }
        vwClear!!.setOnClickListener {
            LogConsole.logList.clear()
            vwLogList!!.adapter = adapter
        }
    }
}
